"""MySites URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/2.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
import xadmin
from django.conf.urls import url,include
from django.contrib import admin
from SitesApp import views
from SitesApp.admin import mysite
from SitesApp.models import User
from rest_framework import routers, serializers, viewsets

#Serializers定义API表示。
class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('uName', 'uPwd','uIP', 'uEmail', 'uNickName')

#ViewSets定义视图行为。
class UserViewSet(viewsets.ModelViewSet):
    queryset = User.uManager.all()
    serializer_class = UserSerializer

#路由器提供了一种自动确定URL conf的简单方法。
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)

urlpatterns = [
    # django内置的后台管理
    # url('admin/', mysite.urls),
    # 第三方后台管理xadmin
	url('^xadmin/', xadmin.site.urls),
	# 首页
    url('^$', views.index),
	url('^home/', views.index),
	# 打分旧地址
	url('^vote/shareNav/',views.shareNav),
	url('^app/',include('SitesApp.urls',namespace='sitesApp')),
	url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),

]
